﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        * {
            font-size: 12px;
        }

        #divResult {
            border: 1px solid #000;
            width: 250px;
        }
    </style>
    <script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <%--<script src="Scripts/myJS.js" type="text/javascript"></script>--%>
    <script type="text/javascript">
        $(function () {
            function send() {
                //向comet_broadcast.ashx发送请求，消息体为文本框content中的内容，请求接收类为AsnyHandler
                $.post("comet_broadcast.ashx", { content: $("#content").val() });

                //清空内容
                $("#content").val("");
            }

            function wait() {
                $.post("comet_broadcast.ashx", {
                    content: "-1"
                },
                     function (data, status) {
                         var result = $("#divResult");
                         result.html(result.html() + "<br/>" + data);

                         //服务器返回消息,再次立连接
                         wait();
                     }, "html"
                 );
            }

            //初始化连接
            wait();

            $("#btnSend").click(function () { send(); });
            $("#content").keypress(function (event) {
                if (event.keyCode == 13) {
                    send();
                }
            });
        });
    </script>
</head>
<body>
    <label>
        <span>广播内容:</span>
        <input type="text" id="content" /><br />
    </label>
    <input type="button" id="btnSend" value="广播" />
    <hr />
    <div>消息记录：</div>
    <div id="divResult" style="min-height: 30px;"></div>
</body>
</html>
